package com.GlobalPaint.app.Adapter;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.HuoQuBean;
import com.GlobalPaint.app.ui.Home.friend.QunLiaoFragment;
import com.GlobalPaint.app.ui.Home.friend.QunLiaoWzhiActivity;
import com.GlobalPaint.app.utils.DataManager;
import com.jcodecraeer.xrecyclerview.XRecyclerView;
import com.jzy.message.activities.QunliaoChatActivity;
import com.mcxtzhang.swipemenulib.SwipeMenuLayout;

import java.util.List;

/**
 * Created by Administrator on 2018/1/18 0018.
 */

public class QunliaoActivityAdapter extends XRecyclerView.Adapter<QunliaoActivityAdapter.ViewHoler>{
    List<List<HuoQuBean.DataBean>> bean;
    private QunLiaoFragment qunLiaoFragment;
    public QunliaoActivityAdapter(List<List<HuoQuBean.DataBean>> list, QunLiaoFragment qunLiaoFragment) {
        bean=list;
        this.qunLiaoFragment=qunLiaoFragment;
    }

    @Override
    public QunliaoActivityAdapter.ViewHoler onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_qunliao_item, parent, false);
        QunliaoActivityAdapter.ViewHoler holder = new QunliaoActivityAdapter.ViewHoler(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(final QunliaoActivityAdapter.ViewHoler holder, final int position) {
        String roomname=bean.get(position).get(0).getRoomname()==
                null?"":bean.get(position).get(0).getRoomname();
        holder.tv_nick.setText(roomname);
        holder.tv_guiji.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(view.getContext(), QunLiaoWzhiActivity.class);
                intent.putExtra("Roomname",bean.get(position).get(0).getRoomname());
                view.getContext().startActivity(intent);
            }
        });
        holder.rl_share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent1=new Intent(view.getContext(), QunliaoChatActivity.class);
                intent1.putExtra("from", bean.get(position).get(0).getRoomname());
                intent1.putExtra("fromid", bean.get(position).get(0).getId());
                intent1.putExtra("userid",  DataManager.userEntity.getUserId());
                intent1.putExtra("hynicheng", DataManager.userEntity.getfNickName());
                intent1.putExtra("avatar", DataManager.userEntity.getUserName());
                intent1.putExtra("RealName", DataManager.userEntity.getfNickName());
                view.getContext().startActivity(intent1);
            }
        });
        holder.btndel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                int userid=bean.get(position).get(0).getUserid();
                String Roomname=bean.get(position).get(0).getRoomname();
                qunLiaoFragment.deleteUser(userid,Roomname,position);
                holder.swi.smoothClose();
            }
        });
    }

    @Override
    public int getItemCount() {
        return bean.size();
    }

    public class ViewHoler extends RecyclerView.ViewHolder {

        private final TextView tv_name;
        private final TextView tv_nick;
        private final TextView tv_guiji;
        private final RelativeLayout rl_share;
        private final SwipeMenuLayout swi;
        private final Button btndel;
        View mview;

        public ViewHoler(View itemView) {
            super(itemView);
            mview = itemView;
            tv_name = (TextView)itemView.findViewById(R.id.tv_name);
            tv_nick = (TextView)itemView.findViewById(R.id.tv_nick);
            tv_guiji = (TextView)itemView. findViewById(R.id.tv_guiji);
            rl_share = (RelativeLayout)itemView. findViewById(R.id.rl_share);
            swi = (SwipeMenuLayout) itemView.findViewById(R.id.swi);
            btndel = (Button)itemView. findViewById(R.id.btndel);
        }
    }
}
